﻿@model List<Models.SystemSetting>

@{
    ViewData["Title"] = "收款信息";
    var name = Model.FirstOrDefault(f => f.OtherType == ((int)Code.SystemType.收款人).ToString());
    var bank = Model.FirstOrDefault(f => f.OtherType == ((int)Code.SystemType.收款银行).ToString());
    var account = Model.FirstOrDefault(f => f.OtherType == ((int)Code.SystemType.收款账号).ToString());
    var alipay = Model.FirstOrDefault(f => f.OtherType == ((int)Code.CashType.支付宝).ToString());
    var wechat = Model.FirstOrDefault(f => f.OtherType == ((int)Code.CashType.微信).ToString());

    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>@ViewData["Title"]</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <environment include="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" media="all" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" asp-append-version="true" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" asp-append-version="true" media="all" />
    </environment>
</head>
<body id="iosiframe">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">@ViewData["Title"]</div>
                    <form class="layui-form" action="" lay-filter="component-form-element">
                        <div class="layui-card-body layui-row layui-col-space10">
                            <fieldset class="layui-elem-field layui-field-title">
                                <legend>银行卡</legend>
                            </fieldset>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <label class="layui-form-label">收款人</label>
                                    <div class="layui-input-block">
                                        @if (name != null) {
                                            <input name="name" value="@name.Values" id="name" placeholder="" lay-verify="" class="layui-input" />
                                        } else {

                                            <input name="name" value="" id="name" placeholder="" lay-verify="" class="layui-input" />
                                        }
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <label class="layui-form-label">收款银行</label>
                                    <div class="layui-input-block">
                                        @if (bank != null) {
                                            <input name="bank" value="@bank.Values" id="bank" placeholder="" lay-verify="" class="layui-input" />
                                        } else {
                                            <input name="bank" value="" id="bank" placeholder="" lay-verify="" class="layui-input" />
                                        }
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <label class="layui-form-label">收款卡号</label>
                                    <div class="layui-input-block">
                                        @if (account != null) {
                                            <input name="account" value="@account.Values" id="account" placeholder="" lay-verify="" class="layui-input" />
                                        } else {
                                            <input name="account" value="" id="account" placeholder="" lay-verify="" class="layui-input" />
                                        }

                                    </div>
                                </div>
                            </div>
                            <fieldset class="layui-elem-field layui-field-title">
                                <legend>支付宝</legend>
                            </fieldset>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <label class="layui-form-label"></label>
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn" id="alipayUploadimg">上传图片</button><input class="layui-upload-file" type="file" accept="undefined">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item" id="alipay_img" style="display:none;">
                                <div class="layui-col-lg6">
                                    <label class="layui-form-label"></label>
                                    <div class="layui-upload">
                                        @if (alipay != null) {
                                            <input type="hidden" id="alipay" name="alipay" value="@alipay.Values" />
                                        } else {
                                            <input type="hidden" id="alipay" name="alipay" value="" />
                                        }
                                        <img class="layui-upload-img" style="width:50%; height:50%" id="alipayImg">
                                    </div>
                                </div>
                            </div>
                            <fieldset class="layui-elem-field layui-field-title">
                                <legend>微信</legend>
                            </fieldset>
                            <div class="layui-form-item">
                                <div class="layui-col-lg6">
                                    <label class="layui-form-label"></label>
                                    <div class="layui-upload">
                                        <button type="button" class="layui-btn" id="wechatUploadimg">上传图片</button><input class="layui-upload-file" type="file" accept="undefined">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item" id="wechat_img" style="display:none;">
                                <div class="layui-col-lg6">
                                    <label class="layui-form-label"></label>
                                    <div class="layui-upload">
                                        @if (wechat != null) {
                                            <input type="hidden" id="wechat" name="wechat" value="@wechat.Values" />
                                        } else {
                                            <input type="hidden" id="wechat" name="wechat" value="" />
                                        }
                                        <img class="layui-upload-img" style="width:50%; height:50%" id="wechatImg">
                                    </div>
                                </div>
                            </div>
                            <fieldset class="layui-elem-field layui-field-title"></fieldset>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="component-form-element">立即提交</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script src="~/layer/layui.js"></script>
    <script>
        layui.config({
            base: '../../layer/' //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['form', 'upload', 'layedit'], function () {
            var $ = layui.$
                , form = layui.form
                , upload = layui.upload;

            var ua = navigator.userAgent.toLowerCase();
            var screenwidth = window.screen.width;
            if (!/iphone|ipad|ipod/.test(ua)) {
                $("#iosiframe").attr("scrolling", "auto");
            } else {
                $('#iosiframe').width(screenwidth + 'px');
            }

            if ($('#alipay')) {
                var src = $('#alipay').val();

                if (src && src.length > 0) {
                    $('#alipayImg').attr('src', src);
                    $('#alipay_img').show();
                }
            }

            if ($('#wechat')) {
                var src = $('#wechat').val();

                if (src && src.length > 0) {
                    $('#wechatImg').attr('src', src);
                    $('#wechat_img').show();
                }
            }

            var uploadAlipay = upload.render({
                elem: '#alipayUploadimg'
                , url: '@Url.Action("filesave", "api")'
                , accept: 'images'
                , size: 2048
                , done: function (res, index, upload) {
                    console.log(res);
                    console.log(upload);
                    if (res.code == 0) {
                        $('#alipayImg').attr('src', res.data.src);
                        $('#alipay_img').show();
                        $('#alipay').val(res.data.src);
                    } else {
                        alert(res.msg);
                    }
                }
            });

            var uploadWechat = upload.render({
                elem: '#wechatUploadimg'
                , url: '@Url.Action("filesave", "api")'
                , accept: 'images'
                , size: 2048
                , done: function (res, index, upload) {
                    console.log(res);
                    console.log(upload);
                    if (res.code == 0) {
                        $('#wechatImg').attr('src', res.data.src);
                        $('#wechat_img').show();
                        $('#wechat').val(res.data.src);
                    } else {
                        alert(res.msg);
                    }
                }
            });


            form.render(null, 'component-form-element');

            //提交
            form.on('submit(component-form-element)', function (data) {
                console.log(data);
                if (data.field.Remittance == 1) {
                    data.field.Remittance = "银行卡";
                }
                else if (data.field.Remittance == 2) {
                    data.field.Remittance = "支付宝";
                }
                else {
                    data.field.Remittance = "微信";
                }
                $.ajax({
                    url: '@Url.Action("savesetting","api")',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(data.field),
                    type:'post'
                }).fail(function (jqXHR, textStatus, errorThrown) {
                    alert(errorThrown, { icon: 2, title: textStatus });
                }).done(function (res) {
                    layer.msg(res.message, { offset: '15px', icon: (res.code == 0 ? 1 : 2), time: 1000 });
                });
                return false;
            });


        });

    </script>
</body>
</html>
